import Vue from 'vue'
import VueRouter from 'vue-router'
import UserHome from '../views/UserHome.vue'
import adminLogin from "../views/manager/Login";
import userLogin from "../views/user/Login"
import Manager from "../views/ManagerHome";
import Message from "../views/message/WallMessage";
import PublishMessage from "../views/user/PublishMessage";
import SelfMessage from "../views/user/SelfMessage";
import UpdatePassword from "../views/user/UpdatePassword";
import MyWallMessage from "../views/user/MyWallMessage"
import UpdateFace from "../views/user/UpdateFace";
import Registion from "../views/user/Registion";
import ElementUI from 'element-ui';
import Log from "../views/Log";
import ManagerHome from "../views/ManagerHome";
import UpdatePassword2 from "../views/manager/UpdatePassword";
import Check from "../views/manager/Check";


Vue.use(VueRouter)

const routes = [
    {
        path: '/userlogin',
        name: '用户登录',
        component: userLogin,
        hidden: true,
        isAble:true,
    },
    {
        path: '/adminlogin',
        name: '管理员登录',
        component:adminLogin,
        hidden: true,
        isAble:true,
    },
    {
        path: '/registion',
        name: '用户注册',
        component:Registion,
        hidden: true,
        isAble:true,
    },

    {
        path: '/',
        name: '心愿墙',
        component: UserHome,
        isAble:true,
        children: [
            {
                path: '/publishMessage',
                name: '发布你的墙消息',
                component: PublishMessage
            },
            {
                path: '/message',
                name: '查看大家的墙消息',
                component: Message
            },
            {
                path: '/selfMessage',
                name: '个人信息',
                hidden:true,
                component: SelfMessage
            },
            {
                path: '/UpdatePassword',
                name: '修改密码',
                hidden:true,
                component: UpdatePassword
            },
            {
                path: '/MyWallMessage',
                name: '我的墙消息',
                hidden:true,
                component:MyWallMessage
            },
            {
                path: '/updateFace',
                name: '修改头像',
                hidden:true,
                component:UpdateFace
            },
            {
                path: '/log',
                name: '用户注册',
                component:Log,
                hidden: true
            },
        ]
    },
    {
        path: '/manager',
        name: '心愿墙管理员',
        component: ManagerHome,
        hidden:true,
        isAble:false,
        children: [

            {
                path: '/AdminUpdatePassword',
                name: '修改密码',
                hidden:true,
                component: UpdatePassword2
            },
            {
                path: '/checkMessage',
                name: '审核墙消息',
                component: Check
            },
            {
                path: '/log',
                name: '心愿墙日志',
                component:Log,
                hidden: true
            },
        ]
    },


]

const router = new VueRouter({
    routes
})

router.beforeEach((to,from,next)=>{
    if(to.name === '发布你的墙消息' && window.sessionStorage.getItem("user") == null){
        router.push('/userLogin');
        ElementUI.Message("请先登录")
    }else
    next();
})



export default router
